/*
 * GConnection.java
 *
 * Created on 13 maart 2008, 15:32
 *
 * @author wijnand.schepens@hogent.be & Ben Willekens
 */
package model.graphic.objects;

import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import model.graphic.locations.Location;
import view.GUI.graphic.GraphicView;

public abstract class GConnection extends Graphical implements Serializable {

    protected Location source;
    protected Location target;
    protected GSine line;//Line2D line;
    protected Polygon polygon;

    public GConnection() {
    }

    public GConnection(Location source, Location target) {
        this.source = source;
        this.target = target;
        line = new GSine();//Line2D.Double();
        line.setLine(source.getX(), source.getY(), source.getX(), source.getY());
        polygon = new Polygon();
        createPolygon();
    }

    public abstract void paint(Graphics2D g);

    /*
     * @return the type representing the class
     */
    public abstract String getString();

    @Override
    public boolean contains(int x, int y) {
        createPolygon();
        return polygon.contains(x + this.getX(), y + this.getX());
    }

    private void createPolygon() {
        polygon = line.createPolygon();
    }

    /**
     * @return the input
     */
    public Location getSource() {
        return source;
    }

    /**
     * @param input the input to set
     */
    public void setSource(Location source) {
        this.source = source;
    }

    /**
     * @return the triangle
     */
    public Location getTarget() {
        return target;
    }

    /**
     * @param triangle the triangle to set
     */
    public void setTarget(Location target) {
        this.target = target;
    }

    /**
     * @return the line
     */
    public GSine getLine() {
        return line;
    }

    /**
     * @param line the line to set
     */
    public void setLine(GSine line) {
        this.line = line;
    }


    @Override
    public void mouseReleased(MouseEvent e) {
        if(e.isPopupTrigger()){
            GraphicView gv = (GraphicView) this.getParent();
            gv.getPopup().menuConnection(this);
            gv.getPopup().getPopup().show(this, e.getX(), e.getY());
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
    }
}
